//
//  DoctorListCell.m
//  QuickCure
//
//  Created by Cyan on 16/9/12.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "DoctorListCell.h"
#import "DoctorListModel.h"


@interface DoctorListCell ()

@property (nonatomic, strong) UIImageView *doctorIcon;

@property (nonatomic, strong) UILabel *nameLabel;

@property (nonatomic, strong) UILabel *postLabel;

@property (nonatomic, strong) UILabel *hosLabel;

@property (nonatomic, strong) UIButton *matchSocreButton;

@property (nonatomic, strong) UIButton *plusButton;

@property (nonatomic, strong) UIButton *flowerButton;

@property (nonatomic, strong) UIButton *starButton;

@end


@implementation DoctorListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
#pragma mark - 初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {

        [self setupMySubviews];
    }
    
    return self;
}

#pragma mark - 设置控件数据
- (void)setModel:(DoctorListModel *)model {
    
    _model = model;
    
    /**
     *
     *  doctor_gender = 1;
     doctor_id = 200000100;
     hospital_name = 北京协和医院;
     doctor_portrait = http://iosapi.itcast.cn/image/elarge_0ce52dde-3551-4086-bd6f-3421838e319d.jpg;
     flower = 1;
     doctor_title_id = 0;
     doctor_title_name = 其他;
     banner = 1;
     doctor_name = 姜伟;
     easymob_id = <null>;
     doctor_attention_id = 148;
     hospital_id = 1;
     operation_count = 1;
     */
    
    self.nameLabel.text = model.doctor_name;
    
    self.postLabel.text = model.doctor_title_name;
    
    self.hosLabel.text = model.hospital_name;
    
    [self.matchSocreButton setTitle:[NSString stringWithFormat:@"匹配度 %d%%",arc4random_uniform(100)] forState:UIControlStateNormal];
    
    [self.plusButton setTitle:[NSString stringWithFormat:@"%ld",model.flower.integerValue] forState:UIControlStateNormal];
    
    [self.starButton setTitle:[NSString stringWithFormat:@"%ld",model.operation_count.integerValue] forState:UIControlStateNormal];
    
    
    [self.flowerButton setTitle:[NSString stringWithFormat:@"%ld",model.doctor_attention_id.integerValue] forState:UIControlStateNormal];

}

 #pragma mark - 设置控件约束
- (void)setupMySubviews {

    
    [self.matchSocreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(-10);
        make.trailing.equalTo(self.contentView).offset(-40);
        make.height.equalTo(@80);
        make.width.equalTo(@60);
    }];

    
    // doctor's icon
    [self.doctorIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.leading.equalTo(self.contentView).offset(10);
        make.height.equalTo(@80);
        make.width.equalTo(@80);
    }];
    
    // doctor's name
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(_doctorIcon.mas_trailing).offset(5);
        make.top.equalTo(self.contentView).offset(10);
        make.height.equalTo(@30);
//        make.width.equalTo(@80);
    }];
    
    // doctor's post
    [self.postLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_nameLabel.mas_bottom);
        make.height.equalTo(@30);
        make.trailing.equalTo(_matchSocreButton.mas_leading).offset(5);
        make.leading.equalTo(_nameLabel.mas_trailing).offset(5);
    }];
    // doctor's hospital
    [self.hosLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(_doctorIcon.mas_trailing).offset(5);
        make.trailing.equalTo(_matchSocreButton.mas_leading).offset(5);
        make.height.equalTo(@30);
        make.top.equalTo(_nameLabel.mas_bottom);
    }];
   
    
    // doctor's operation Count
    [self.plusButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(_doctorIcon.mas_trailing);
        make.top.equalTo(_hosLabel.mas_bottom);
        make.width.equalTo(@50);
    }];
    
    
    // doctor's flower
    [self.flowerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_plusButton.mas_bottom);
        make.leading.equalTo(_plusButton.mas_trailing);
//        make.height.equalTo(@30);
        make.width.equalTo(@60);
    }];
    [self.starButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_flowerButton.mas_bottom);
//        make.height.equalTo(@30);
        make.width.equalTo(@50);
        make.leading.equalTo(_flowerButton.mas_trailing);
    }];

    
}



#pragma mark - 控件懒加载
// starButton(doctor got stars)
-(UIButton *)starButton {
    
    if (!_starButton) {
        _starButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self.contentView addSubview:_starButton];
        
        [_starButton setTitleColor:kThemeColor forState:UIControlStateNormal];
        [_starButton setImage:[UIImage imageNamed:@"jinqi"] forState:UIControlStateNormal];
//        [_starButton setBackgroundColor:[UIColor greenColor]];
        [_starButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 0)];
        [_starButton.titleLabel setFont:[UIFont systemFontOfSize:14]];

    }
    return _starButton;
}


// flowerButton(doctor's flowers)
-(UIButton *)flowerButton {
    if (!_flowerButton) {
        _flowerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self.contentView addSubview:_flowerButton];
        [_flowerButton setTitleColor:kThemeColor forState:UIControlStateNormal];
        [_flowerButton.titleLabel setFont:[UIFont systemFontOfSize:14]];

        [_flowerButton setImage:[UIImage imageNamed:@"xianhua"] forState:UIControlStateNormal];
//        [_flowerButton setBackgroundColor:[UIColor yellowColor]];
        [_flowerButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 0)];
    }
    
    return _flowerButton;
}


// plusButton
- (UIButton *)plusButton {
    if (!_plusButton) {
        
        _plusButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self.contentView addSubview:_plusButton];
        [_plusButton setTitleColor:kThemeColor forState:UIControlStateNormal];
        [_plusButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        [_plusButton setImage:[UIImage imageNamed:@"yuyueliang"] forState:UIControlStateNormal];
//        [_plusButton setBackgroundColor:[UIColor redColor]];
        [_plusButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 0)];


    }
    return _plusButton;
}



//matchSocreButton
- (UIButton *)matchSocreButton {
    
    if (!_matchSocreButton) {
        _matchSocreButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        
//        [_matchSocreButton setImage:[UIImage imageNamed:@"pipeidu"] forState:UIControlStateNormal];
        [_matchSocreButton setBackgroundImage:[UIImage imageNamed:@"pipeidu"] forState:UIControlStateNormal];
        [self.contentView addSubview:_matchSocreButton];
        [_matchSocreButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        _matchSocreButton.titleLabel.numberOfLines = 0;
        _matchSocreButton.titleLabel.textAlignment = NSTextAlignmentCenter;
//        [self.contentView bringSubviewToFront:_matchSocreButton];

    }
    return _matchSocreButton;
    
}


// hosLabel
- (UILabel *)hosLabel {
    
    if (!_hosLabel) {
        _hosLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self.contentView addSubview:_hosLabel];
        _hosLabel.numberOfLines = 2;
        _hosLabel.textAlignment = NSTextAlignmentLeft;
        _hosLabel.textColor = [UIColor lightGrayColor];
        _hosLabel.font = [UIFont systemFontOfSize:18];
        
    }
    return _hosLabel;
}

// postLabel
- (UILabel *)postLabel {
    if (!_postLabel) {
        _postLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self.contentView addSubview:_postLabel];
        
        _postLabel.textColor = [UIColor lightGrayColor];
        _postLabel.textAlignment = NSTextAlignmentLeft;
        _postLabel.font = [UIFont systemFontOfSize:16];
        
    }
    return _postLabel;
}


// nameLabel
- (UILabel *)nameLabel {
    
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:_nameLabel];
    }
    return _nameLabel;
}


// doctorIcon
- (UIImageView *)doctorIcon {
    
    if (!_doctorIcon) {
        _doctorIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        
        _doctorIcon.image = [UIImage imageNamed:@"illness_img_person.png"];
        
        [_doctorIcon sizeToFit];
        
        [self.contentView addSubview:_doctorIcon];
    }
    return _doctorIcon;
}




@end
